package java_class_work.week06;

import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;

/**
 * @Auther: admin
 * @Date: 2022/10/17 10:15
 * @Description: 特点： 不重复且有序
 */

public class HashSetDemo01 {
    public static void main(String[] args) {
        HashSet<Integer> hs = new HashSet<>();
        hs.add(1);
        hs.add(3);
        hs.add(8);
        hs.add(5);
        hs.add(3);
        // 迭代器遍历
        Iterator<Integer> iterator = hs.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
            iterator.remove();
        }
        // foreach 遍历
        System.out.println("foreach:");
        hs.forEach(System.out::println);
    }
}
